#include "typeframe.h"
#include "typeframe_p.h"
#include "ui_typeframe.h"

TypeFramePrivate::TypeFramePrivate(TypeFrame *parent) :
    QObject(parent),
    q(parent)
{

}

TypeFramePrivate::~TypeFramePrivate()
{

}

void TypeFramePrivate::initializeMember()
{
    q->ui->lineEdit->setFocusPolicy(Qt::StrongFocus);
}

void TypeFramePrivate::connectSignalsAndSlots()
{
    connect(this,                   SIGNAL(sendMessage(QVariant)),
            q,                      SIGNAL(sentMessage(QVariant)));
    connect(q->ui->send,            SIGNAL(clicked()),
            this,                   SLOT(returnPressed()));
    connect(q->ui->lineEdit,        SIGNAL(returnPressed()),
            this,                   SLOT(returnPressed()));
}

void TypeFramePrivate::completeConstruct()
{

}

void TypeFramePrivate::returnPressed()
{
    const QString mesg = q->ui->lineEdit->text();

    if(!mesg.isEmpty())
        emit sendMessage(mesg);

    q->ui->lineEdit->clear();
}

TypeFrame::TypeFrame(QWidget *parent) :
    QFrame(parent),
    ui(new Ui::TypeFrame),
    d(new TypeFramePrivate(this))
{
    ui->setupUi(this);

    d->initializeMember();
    d->connectSignalsAndSlots();
    d->completeConstruct();
}

TypeFrame::~TypeFrame()
{
    delete ui;
    delete d;
}

QPushButton *TypeFrame::changeToHandWriting() const
{
    return ui->changeToHandWriting;
}

void TypeFrame::changeEvent(QEvent *e)
{
    QFrame::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
